package com.zxl.springcloud.service.impl;

import com.zxl.springcloud.entity.Student;
import com.zxl.springcloud.dao.StudentDao;
import com.zxl.springcloud.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao dao;

    @Override
    public List<Student> findAll() {
        return dao.findAll();
    }

    @Override
    public Student get(long id) {
        // 使用 dao.getOne(id) 返回的是代理对象，此处使用findById(id)
        return dao.findById(id).get();
    }

    @Override
    public boolean add(Student student) {
        return dao.saveAndFlush(student)!=null;
    }
}
